import { Body, Controller, Post, UseInterceptors } from '@nestjs/common';
import { AuthService } from './auth.service';
import { BaseController } from 'src/common/BaseController';
import { User } from '../user/entities/user.entity';
import { ResponsInterceptoreBase } from 'src/transform.interceptor';
import { ApiOperation, ApiTags } from '@nestjs/swagger';
import { LoginDto } from './dto/login.dto';
import { Public } from 'src/app.decorator';
@Controller('auth')
@ApiTags('用户登录')
@UseInterceptors(ResponsInterceptoreBase)
export class AuthController extends BaseController<User, AuthService> {
    constructor(private readonly authService: AuthService) {
        super(authService); // Pass the service to the base controller
    }

    @Post('login')
    @Public()
    @ApiOperation({ summary: '用户登录' })
    async login(@Body() LoginDto: LoginDto) {
        let result = await this.authService.login(LoginDto.username, LoginDto.password);
        if(result[0]){
            return this.Success(result[1], "登录成功");
        }else{
            return this.Fail(result[1], "用户名或密码错误");
        }
        
    }

}
